package com.etime.shycourse.controller.accountonline;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.etime.shy.common.BaseMessage;
import com.etime.shy.common.ListMessage;
import com.etime.shycourse.config.PageMessage;
import com.etime.shycourse.dto.SettlementDto;
import com.etime.shycourse.dto.SysUserDto;
import com.etime.shycourse.services.account.interfaces.AccountFinanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 在线课程结算数据接口
 */
@Api(tags = "后台-在线课程结算接口(财务接口)")
@RestController
@RequestMapping("/sys/account/finance")
public class AccountFinanceController {

    @Autowired
    private AccountFinanceService accountFinanceService;

    /*
     *  分页查询提成记录
     * */
    @ApiOperation("分页查询所有")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pagenum",value = "第几页"),
            @ApiImplicitParam(name = "pagesize",value = "每页多少行"),
            @ApiImplicitParam(name="settlementpay",value="是否支付 传递数字 0代表未支付"),
            @ApiImplicitParam(name="roleid",value="roleid 传递数字"),
    })
    @RequestMapping("/page")
    public PageMessage<SettlementDto> getAll(long pagenum,long pagesize,int settlementpay,int settlementtype){
        PageMessage<SettlementDto> msg = new PageMessage<>();
        Page<SettlementDto> allGroupByUser = accountFinanceService.getAllSettlements(settlementpay, pagenum, pagesize,settlementtype);
        msg.setPagedata(allGroupByUser);
        msg.setCode(1);
        msg.setMsg("分页查询成功");
        return msg;

    }

    /*
     *  提成记录明细  支付明细
     * */
    @ApiOperation("查询明细")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "id"),
            @ApiImplicitParam(name = "settlementpay",value = "settlementpay"),
            @ApiImplicitParam(name="pagenum",value="第几页"),
            @ApiImplicitParam(name="pagesize",value="每页多少行"),
    })
    /*
    * 分页查询结算详情
    * */
    @RequestMapping("page/detail")
    public PageMessage<SettlementDto> detail( int id,int settlementpay,long pagenum,long pagesize){
        PageMessage<SettlementDto> settlementDtoPageMessage = new PageMessage<>();
        Page<SettlementDto> settlementDto =
                accountFinanceService.findUserAndSettlementInfo(id, settlementpay, pagenum, pagesize);
        settlementDtoPageMessage.setPagedata(settlementDto);
        settlementDtoPageMessage.setCode(1);
        settlementDtoPageMessage.setMsg("查询明细成功");
        return settlementDtoPageMessage;
    }

    /*
    * 不分页查询结算详情
    * */
    @RequestMapping("/detail")
    public ListMessage<SettlementDto> details(int id, int settlementpay){
        List<SettlementDto> userAndSettlementInfo = accountFinanceService.getUserAndSettlementInfo(id, settlementpay);
        ListMessage<SettlementDto> msg = new ListMessage<>();
        msg.setDatalist(userAndSettlementInfo);
        return msg;
    }
    @ApiOperation("分页查询所有")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "settlements",value = "数组"),

    })

    /*
    * 支付提成订单
    * */
    @RequestMapping("/pay")
    public BaseMessage pay(int[] settlementids){

        BaseMessage baseMessage = new BaseMessage();
        System.out.println(Arrays.toString(settlementids));
       int count = accountFinanceService.pay(settlementids);
       if(count>0){
           baseMessage.setCode(1);
           baseMessage.setMsg("支付成功");
           return baseMessage;
       }else{
           baseMessage.setCode(0);
           baseMessage.setMsg("支付失败");
           return baseMessage;
       }
    }



    @RequestMapping("/dateList")
    public PageMessage<Date> getDateList(long pagenum,long pagesize,int settlementpay){
        PageMessage<Date> datePageMessage = new PageMessage<>();
        Page<Date> dateList = accountFinanceService.getDateList(pagenum,pagesize,settlementpay);
        datePageMessage.setPagedata(dateList);
        datePageMessage.setCode(1);
        return datePageMessage;
    }

    /*
    * 打印
    * */
    @RequestMapping("/print")
    public void print(int[] settlementids, String type,HttpServletResponse response){
        System.out.println(Arrays.toString(settlementids));
        accountFinanceService.print(settlementids,response,type);
    }


    @ApiOperation("查询日期列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="pagenum",value="第几页"),
            @ApiImplicitParam(name="pagesize",value="每页多少行"),
            @ApiImplicitParam(name="settlementpay",value="是否支付"),
            @ApiImplicitParam(name="userid",value="用户id"),

    })
    @RequestMapping("/findDateList")
    public PageMessage<Date> findDateList(long pagenum,long pagesize,int settlementpay,Integer id,String type){
        PageMessage<Date> msg = new PageMessage<>();
        Page<Date> settlementDtoList= accountFinanceService.findDateList(pagenum,pagesize,settlementpay,id,type);
        msg.setPagedata(settlementDtoList);
        msg.setCode(1);
        return msg;
    }
    /*
    * 通过日期获取settlement结算信息
    * */
    @RequestMapping("/getSettlementByDate")
    public ListMessage<SettlementDto> getSettlementByDate(int settlementpay,String settlementtime,int id,String type){
        ListMessage<SettlementDto> msg = new ListMessage<>();
        List<SettlementDto> settlementDtoPage = accountFinanceService.getSettlementByDate(settlementpay,settlementtime,id, type);
        msg.setDatalist(settlementDtoPage);
        msg.setCode(1);
        return msg;
    }

}
